// 仓库UI
const ui = UiScreen.getAllScreen().find(e => e.name == "main") // 声明当前脚本的screen

// 仓库
const open_warehouse_button = ui.findChildByName("仓库入口")
const warehouse = ui.findChildByName('仓库')
const closeButton = warehouse.findChildByName('关闭')
const contents = warehouse.findChildByName('Content')
const contentThing = contents.findChildByName('物品')
contentThing.visible = false;
const allThing = [];

for (let i = 0; i < 4 * 8; i++) {
    const clone_thing = contentThing.clone()
    clone_thing.visible = true;
    let name = '无'
    let image = 'picture/empty.png'
    if (i > 12) {
        image = 'picture/未解锁.png'
        name = ''
    }
    clone_thing.findChildByName('图片').image = image
    clone_thing.findChildByName('名称').textContent = name
    allThing.push(clone_thing)
}

closeButton.events.on('pointerup', () => {
    warehouse.visible = false
});

open_warehouse_button.events.on('pointerup', () => {
    warehouse.visible = true
});

function updateUI(data) {
    for (let { name, image } of data) {
        clone_thing.findChildByName('图片').image = image
        clone_thing.findChildByName('名称').textContent = name
    }
}

remoteChannel.events.on('client', (args) => {
    if (args.type == '仓库') {
        updateUI(args.data)
    }
})